<template>
	<view>
		<view style="font-size:28rpx;line-height:20px;color: #999;padding:20px;">提示：</br>必得分红猫进度默认为4等分模式：看视频次数，邀请人数，合成猫次数、旅行团收益4部分组成， 每部分各占25%，某一部分达到25%以后不再上涨。</br>必得进度达到100%以后，将获得一只永久分红猫，必得进度将不再变化。</br>旅行团收益：为好友给我赚钱的进度，例如设置旅行团收益10元，必得进度1%，单次收益没有达到10元，进度不会增加，直到累计收益达到10元，必得进度才会增加1%。</br>若开启了必得分红猫设置为单一模式：视频次数，邀请人数，合成猫次数、旅行团收益只要其中一项达到100%即可获得永久分红猫。</br>配置参数保存后，前端预计10分钟左右生效。</view>
		<view class="uni-container" style="float: left;">
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="看视频次数" name="title" labelWidth="100">
					<input class="uni-input-border" type="number" v-model="bide.videocount" />
				</uni-forms-item>
				<uni-forms-item label="邀请人数" name="title" labelWidth="100">
					<input class="uni-input-border" type="number" v-model="bide.friendcount" />
				</uni-forms-item>
				<uni-forms-item label="合成次数" name="title" labelWidth="100">
					<input class="uni-input-border" type="number" step = "0.1" v-model="bide.hechengcount" />
				</uni-forms-item>
				<uni-forms-item label="旅行团收益" name="title" labelWidth="100">
					<input class="uni-input-border" type="input" v-model="bide.friendfen" />
				</uni-forms-item>
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">保存</button>
				</view>
			</uni-forms>
		</view>
		
		<view class="uni-container" style="float: left;">
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="得进度:(万分比)" name="title" labelWidth="130">
					<input class="uni-input-border" type="number" v-model="bideprofit.videocount" />
				</uni-forms-item>
				<uni-forms-item label="得进度:(万分比)" name="title" labelWidth="130">
					<input class="uni-input-border" type="number" v-model="bideprofit.friendcount" />
				</uni-forms-item>
				<uni-forms-item label="得进度:(万分比)" name="title" labelWidth="130">
					<input class="uni-input-border" type="number" v-model="bideprofit.hechengcount" />
				</uni-forms-item>
				<uni-forms-item label="得进度:(万分比)" name="title" labelWidth="130">
					<input class="uni-input-border" type="number" v-model="bideprofit.friendfen" />
				</uni-forms-item>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading:false,
				"bide":{
					"videocount":0,        // 看视频次数
					"friendcount":0,       // 邀请人数
					"hechengcount":0,      // 合成狗次数
					"friendfen":0,         // 旅行团收益   分
				},    
					
				// 满足一次   给多少必得收益
				"bideprofit":{
					"videocount":0,           // 百分比
					"friendcount":0,           // 百分比
					"hechengcount":0,           // 百分比
					"friendfen":0,           // 百分比
				},
			}
		},
		methods: {
			getinfo(){
				var self = this
				this.isLoading = true
				self.data = []
				this.$request('admin/loadconfig',{id:'bide'}).then(res => {
					this.isLoading = false
					var json = res.config
					self.bide = json
					console.log(res)
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
				
				this.$request('admin/loadconfig',{id:'bideprofit'}).then(res => {
					this.isLoading = false
					var json = res.config
					var obj = {}
					for(let key in json){
						if(key != '_id'){
							obj[key] = json[key]*100
						}
					}
					self.bideprofit = obj
					console.log(res)
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			},
			save(){
				var self = this
				self.isLoading = true
				delete self.bide._id;
				var obj = {}
				for(let key in self.bideprofit){
					if(key != '_id'){
						obj[key] = parseFloat(self.bideprofit[key])/100
					}
				}
				for(let key in self.bide){
					if(key != '_id'){
						self.bide[key] = parseFloat(self.bide[key])
					}
				}
				console.log(self.bide)
				console.log(obj)
				self.$request('admin/setconfig',{json:JSON.stringify({bideprofit:obj})}).then(res => {
					self.$request('admin/setconfig',{json:JSON.stringify({bide:self.bide})}).then(res => {
						self.isLoading = false
						uni.showToast({
							title: "修改成功",
							icon: 'none',
							duration: 2000
						})
					}).catch(res => {
					
					}).finally(err => {
						this.isLoading = false
					})
					
				}).catch(res => {
				
				}).finally(err => {
					this.isLoading = false
				})
			}
		},
		mounted() {
			var self = this
			self.getinfo()
		}
	}
</script>

<style>

</style>
